﻿using EmitDebugging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Reflection.Emit;

namespace EmitDebugging.Tests
{
	[TestClass]
	public sealed class TypeDebuggingTests : AssemblyCreationTests
	{
		[TestMethod]
		public void CallDisposeAfterDisposing()
		{
			TypeDebugging type = null;

			using(var assembly = AssemblyCreationTests.CreateDebuggingAssembly("Me"))
			{
				using(type = AssemblyCreationTests.CreateDebuggingType(assembly,
					assembly.Builder.GetDynamicModule("Me"), "Type"))
				{
				}
				
				type.Dispose();
			}
		}

		[TestMethod, ExpectedException(typeof(ObjectDisposedException))]
		public void CallGetMethodDebuggingWithConstructorBuilderAfterDisposing()
		{
			TypeDebugging type = null;

			using(var assembly = AssemblyCreationTests.CreateDebuggingAssembly("Me"))
			{
				using(type = AssemblyCreationTests.CreateDebuggingType(assembly,
					assembly.Builder.GetDynamicModule("Me"), "Type"))
				{
				}

				type.GetMethodDebugging(null as ConstructorBuilder);
			}
		}

		[TestMethod, ExpectedException(typeof(ObjectDisposedException))]
		public void CallGetMethodDebuggingWithMethodBuilderAfterDisposing()
		{
			TypeDebugging type = null;

			using(var assembly = AssemblyCreationTests.CreateDebuggingAssembly("Me"))
			{
				using(type = AssemblyCreationTests.CreateDebuggingType(assembly,
					assembly.Builder.GetDynamicModule("Me"), "Type"))
				{
				}

				type.GetMethodDebugging(null as MethodBuilder);
			}
		}
	}
}
